home *** CD-ROM | disk | FTP | other *** search
/ Macworld Expo - Develope…Central & Net Innovations / Developer Central and Net Innovators (MacWorld Expo) (January 1999).iso / Developer Central / Bowers Development / Demo AppMaker / Examples / plain C OS8 / Everything / Buttons.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-10-29  |  11.6 KB  |  496 lines  |  [TEXT/CWIE]

  1. /* Buttons.c */
  2.  
  3. #include <Types.h>
  4. #include <Quickdraw.h>
  5. #include <Controls.h>
  6. #include <Dialogs.h>
  7. #include <Events.h>
  8. #include <Lists.h>
  9. #include <Menus.h>
  10. #include <Resources.h>
  11. #include <Sound.h>
  12. #include <TextEdit.h>
  13. #include <ToolUtils.h>
  14. #include <Appearance.h>
  15. #include <stdlib.h>
  16.  
  17. #include "Globals.h"
  18. #include "ResourceDefs.h"
  19. #include "DoScrap.h"
  20. #include "Miscellany.h"
  21. #include "Scrolling.h"
  22. #include "ControlUtils.h"
  23. #include "Dispatcher.h"
  24. #include "DDocData.h"
  25. #include "EverythingEngine.h"
  26. #include "EverythingDoc.h"
  27. #include "Buttons.h"
  28.  
  29.  
  30. static    EverythingEngine*      GetEngine    (Buttons*    self);
  31.  
  32. static    void    DoUndo        (Buttons*    self);
  33. static    void    DoCut        (Buttons*    self);
  34. static    void    DoCopy        (Buttons*    self);
  35. static    void    DoPaste        (Buttons*    self);
  36. static    void    DoClear        (Buttons*    self);
  37. static    void    DoSelectAll        (Buttons*    self);
  38. static    void    DoShowClipboard    (Buttons*    self);
  39.  
  40.  
  41. //----------
  42. Buttons*        NewButtons ()
  43. {
  44.     Buttons*        window;
  45.  
  46.     window = (Buttons*)malloc (sizeof (Buttons));
  47.     Buttons_Init (window);
  48.     SetClassID (window, classButtons);
  49.  
  50.     return window;
  51. }
  52.  
  53. //----------
  54. void    DeleteButtons (
  55.     Buttons*        window)
  56. {
  57.     Buttons_Free (window);
  58.     free (window);
  59. }
  60.  
  61. //----------
  62. void    Buttons_Create (
  63.     AMDoc*            inDoc,
  64.     DDocData*        inData)
  65. {
  66.     Buttons*        winObj = NewButtons ();
  67.  
  68.     if (winObj != nil) {
  69.         Buttons_Open (winObj, inDoc, inData);
  70.     }
  71. }
  72.  
  73. //----------
  74. void    Buttons_Init (
  75.     Buttons*        self)
  76. {
  77. }
  78.  
  79. //----------
  80. void    Buttons_Free (
  81.     Buttons*        self)
  82. {
  83. }
  84.  
  85. //----------
  86. EverythingEngine*    GetEngine (
  87.     Buttons*        self)
  88. {
  89.     return (EverythingEngine*) self->super.mDoc->mEngine;
  90. }
  91.  
  92. /*----------*/
  93. void    Buttons_Open (
  94.     Buttons*        self,
  95.     AMDoc*            inDoc,
  96.     DDocData*        inData)
  97. {
  98.     WindowPtr        window;
  99.     Handle            wftb;
  100.  
  101.     self->super.mDoc = inDoc;
  102.     self->mData = inData;
  103.     AddResponder ((AMSignaler*) self->mData, (AMResponder*) self);
  104.  
  105.     window = GetNewCWindow (WIND_Buttons, nil, (WindowPtr) -1L);
  106.     if (AMEngine_GetFilename (self->super.mDoc->mEngine) [0] != 0) {
  107.         SetWTitle (window, AMEngine_GetFilename (self->super.mDoc->mEngine));
  108.     }
  109.     self->super.mWindow = window;
  110.     ((EverythingDoc*)self->super.mDoc)->mButtonsPtr = window;
  111.  
  112.     SetWindowKind (window, 'AM');
  113.     SetWRefCon (window, (long) self);
  114.     SetPort (window);
  115.     SetInfo (window);
  116.  
  117.     wftb = GetResource ('Wftb', WIND_Buttons);
  118.  
  119.     CreateRootControl (window, &self->super.mRootControl);
  120.  
  121.     self->super.vScroll = nil;
  122.     self->super.hScroll = nil;
  123.  
  124.  
  125.     self->mCapInvisibleLabel = GetNewControl (CNTL_CapInvisible, window);
  126.     SetWindowItemFont (self->mCapInvisibleLabel, wftb, 1);
  127.     SetControlFromTEXT (self->mCapInvisibleLabel, TEXT_CapInvisible);
  128.  
  129.     self->mInvisibleHandle = GetNewControl (CNTL_Invisible, window);
  130.     SetWindowItemFont (self->mInvisibleHandle, wftb, 2);
  131.  
  132.     self->mStandardHandle = GetNewControl (CNTL_Standard, window);
  133.     SetWindowItemFont (self->mStandardHandle, wftb, 3);
  134.  
  135.     self->mDefaultHandle = GetNewControl (CNTL_Default, window);
  136.     SetWindowItemFont (self->mDefaultHandle, wftb, 4);
  137.     SetDefaultState (self->mDefaultHandle, true);
  138.  
  139.     self->mBevelHandle = GetNewControl (CNTL_Bevel, window);
  140.     SetWindowItemFont (self->mBevelHandle, wftb, 5);
  141.  
  142.     self->mButtonHandle = GetNewControl (CNTL_Button, window);
  143.     EmbedControl (self->mButtonHandle, self->mBevelHandle);
  144.     SetWindowItemFont (self->mButtonHandle, wftb, 6);
  145.     SetBevelButtonGraphicAlignment (self->mButtonHandle, kControlBevelButtonAlignCenter, 0, 0);
  146.  
  147.     self->mNextHandle = GetNewControl (CNTL_Next, window);
  148.     EmbedControl (self->mNextHandle, self->mBevelHandle);
  149.     SetWindowItemFont (self->mNextHandle, wftb, 7);
  150.     SetBevelButtonTextPlacement (self->mNextHandle, kControlBevelButtonPlaceToRightOfGraphic);
  151.     SetBevelButtonTextAlignment (self->mNextHandle, kControlBevelButtonAlignTextFlushLeft, 0);
  152.     SetBevelButtonGraphicAlignment (self->mNextHandle, kControlBevelButtonAlignLeft, 0, 0);
  153.  
  154.     self->mNext2Handle = GetNewControl (CNTL_Next2, window);
  155.     EmbedControl (self->mNext2Handle, self->mBevelHandle);
  156.     SetWindowItemFont (self->mNext2Handle, wftb, 8);
  157.     SetBevelButtonTextPlacement (self->mNext2Handle, kControlBevelButtonPlaceBelowGraphic);
  158.     SetBevelButtonTextAlignment (self->mNext2Handle, kControlBevelButtonAlignTextCenter, 0);
  159.     SetBevelButtonGraphicAlignment (self->mNext2Handle, kControlBevelButtonAlignTop, 0, 0);
  160.  
  161.     self->mGraphicHandle = GetNewControl (CNTL_Graphic, window);
  162.     SetWindowItemFont (self->mGraphicHandle, wftb, 9);
  163.  
  164.     self->mCapcicnLabel = GetNewControl (CNTL_Capcicn, window);
  165.     EmbedControl (self->mCapcicnLabel, self->mGraphicHandle);
  166.     SetWindowItemFont (self->mCapcicnLabel, wftb, 10);
  167.     SetControlFromTEXT (self->mCapcicnLabel, TEXT_Capcicn);
  168.  
  169.     self->mRightHandle = GetNewControl (CNTL_Right, window);
  170.     EmbedControl (self->mRightHandle, self->mGraphicHandle);
  171.     SetWindowItemFont (self->mRightHandle, wftb, 11);
  172.  
  173.     self->mCapicl8Label = GetNewControl (CNTL_Capicl8, window);
  174.     EmbedControl (self->mCapicl8Label, self->mGraphicHandle);
  175.     SetWindowItemFont (self->mCapicl8Label, wftb, 12);
  176.     SetControlFromTEXT (self->mCapicl8Label, TEXT_Capicl8);
  177.  
  178.     self->mLightHandle = GetNewControl (CNTL_Light, window);
  179.     EmbedControl (self->mLightHandle, self->mGraphicHandle);
  180.     SetWindowItemFont (self->mLightHandle, wftb, 13);
  181.  
  182.     self->mCapICNLabel = GetNewControl (CNTL_CapICN, window);
  183.     EmbedControl (self->mCapICNLabel, self->mGraphicHandle);
  184.     SetWindowItemFont (self->mCapICNLabel, wftb, 14);
  185.     SetControlFromTEXT (self->mCapICNLabel, TEXT_CapICN);
  186.  
  187.     self->mRight2Handle = GetNewControl (CNTL_Right2, window);
  188.     EmbedControl (self->mRight2Handle, self->mGraphicHandle);
  189.     SetWindowItemFont (self->mRight2Handle, wftb, 15);
  190.  
  191.     self->mCapicl9Label = GetNewControl (CNTL_Capicl9, window);
  192.     EmbedControl (self->mCapicl9Label, self->mGraphicHandle);
  193.     SetWindowItemFont (self->mCapicl9Label, wftb, 16);
  194.     SetControlFromTEXT (self->mCapicl9Label, TEXT_Capicl9);
  195.  
  196.     self->mButton2Handle = GetNewControl (CNTL_Button2, window);
  197.     EmbedControl (self->mButton2Handle, self->mGraphicHandle);
  198.     SetWindowItemFont (self->mButton2Handle, wftb, 17);
  199.  
  200.     self->mRight3Handle = GetNewControl (CNTL_Right3, window);
  201.     EmbedControl (self->mRight3Handle, self->mGraphicHandle);
  202.     SetWindowItemFont (self->mRight3Handle, wftb, 18);
  203.  
  204.     self->mCapPICTLabel = GetNewControl (CNTL_CapPICT, window);
  205.     EmbedControl (self->mCapPICTLabel, self->mGraphicHandle);
  206.     SetWindowItemFont (self->mCapPICTLabel, wftb, 19);
  207.     SetControlFromTEXT (self->mCapPICTLabel, TEXT_CapPICT);
  208.  
  209.     self->mRect3DHandle = GetNewControl (CNTL_Rect3D, window);
  210.     SetWindowItemFont (self->mRect3DHandle, wftb, 20);
  211.  
  212.     self->mLeftIconHandle = GetNewControl (CNTL_LeftIcon, window);
  213.     SetWindowItemFont (self->mLeftIconHandle, wftb, 21);
  214.  
  215.     self->mRightIconHandle = GetNewControl (CNTL_RightIcon, window);
  216.     SetWindowItemFont (self->mRightIconHandle, wftb, 22);
  217.  
  218.     self->mTitledPICTHandle = GetNewControl (CNTL_TitledPICT, window);
  219.     SetWindowItemFont (self->mTitledPICTHandle, wftb, 23);
  220.  
  221.     AdvanceKeyboardFocus (window);
  222.  
  223.     ShowWindow (window);
  224. }
  225.  
  226. /*----------*/
  227. void    Buttons_Close (
  228.     Buttons*        self)
  229. {
  230.     RemoveResponder ((AMSignaler*) self->mData, (AMResponder*) self);
  231.  
  232.     ((EverythingDoc*)self->super.mDoc)->mButtonsPtr = nil;
  233.     SetInfo (nil);
  234.     HideWindow (self->super.mWindow);
  235.     DisposeWindow (self->super.mWindow);
  236.  
  237.     DeleteButtons (self);
  238. }
  239.  
  240. /*----------*/
  241. void    Buttons_Track (
  242.     Buttons*        self,
  243.     ControlHandle    whichControl,
  244.     short            whichPart,
  245.     Point            where)
  246. {
  247.     Rect            bounds;
  248.     short            newValue;
  249.  
  250.     if (whichControl == self->mInvisibleHandle) {
  251.         if (TrackClick (self->mInvisibleHandle, where)) {
  252.         }
  253.     }
  254.     if (whichControl == self->mStandardHandle) {
  255.         if (TrackClick (self->mStandardHandle, where)) {
  256.         }
  257.     }
  258.     if (whichControl == self->mDefaultHandle) {
  259.         if (TrackClick (self->mDefaultHandle, where)) {
  260.         }
  261.     }
  262.     if (whichControl == self->mButtonHandle) {
  263.         if (TrackClick (self->mButtonHandle, where)) {
  264.         }
  265.     }
  266.     if (whichControl == self->mNextHandle) {
  267.         if (TrackClick (self->mNextHandle, where)) {
  268.         }
  269.     }
  270.     if (whichControl == self->mNext2Handle) {
  271.         if (TrackClick (self->mNext2Handle, where)) {
  272.         }
  273.     }
  274.     if (whichControl == self->mRightHandle) {
  275.         if (TrackClick (self->mRightHandle, where)) {
  276.         }
  277.     }
  278.     if (whichControl == self->mLightHandle) {
  279.         if (TrackClick (self->mLightHandle, where)) {
  280.         }
  281.     }
  282.     if (whichControl == self->mRight2Handle) {
  283.         if (TrackClick (self->mRight2Handle, where)) {
  284.         }
  285.     }
  286.     if (whichControl == self->mButton2Handle) {
  287.         if (TrackClick (self->mButton2Handle, where)) {
  288.         }
  289.     }
  290.     if (whichControl == self->mRight3Handle) {
  291.         if (TrackClick (self->mRight3Handle, where)) {
  292.         }
  293.     }
  294.     if (whichControl == self->mRect3DHandle) {
  295.         if (TrackClick (self->mRect3DHandle, where)) {
  296.         }
  297.     }
  298.     if (whichControl == self->mLeftIconHandle) {
  299.         if (TrackClick (self->mLeftIconHandle, where)) {
  300.         }
  301.     }
  302.     if (whichControl == self->mRightIconHandle) {
  303.         if (TrackClick (self->mRightIconHandle, where)) {
  304.         }
  305.     }
  306.     if (whichControl == self->mTitledPICTHandle) {
  307.         if (TrackClick (self->mTitledPICTHandle, where)) {
  308.         }
  309.     }
  310. }
  311.  
  312. //----------
  313. void    Buttons_DataChanged (
  314.     Buttons*        self,
  315.     long            inDataID)
  316. {
  317. }
  318.  
  319. /*----------*/
  320. void    Buttons_MouseIn (
  321.     Buttons*        self,
  322.     Point            where,
  323.     short            modifiers)
  324. {
  325.     Rect        bounds;
  326.  
  327. }
  328.  
  329. //----------
  330. void    Buttons_ExitCurField (
  331.     Buttons*        self)
  332. {
  333.     ControlHandle    focus;
  334.  
  335.     GetKeyboardFocus (self->super.mWindow, &focus);
  336.  
  337.     if (focus == nil) {
  338.         // nothing to exit
  339.  
  340.     }
  341. }
  342.  
  343. /*----------*/
  344. void    Buttons_TypeIn (
  345.     Buttons*        self,
  346.     char            ch)
  347. {
  348.     ControlHandle    focus;
  349.     short            keyCode;
  350.  
  351.     GetKeyboardFocus (self->super.mWindow, &focus);
  352.  
  353.     if ((ch == charEnter)
  354.     ||  (ch == charReturn)) {
  355.         Buttons_ExitCurField (self);    // Dispatch
  356.         SimulateClick (self->mDefaultHandle);
  357.     } else if (ch == charEsc) {
  358.     } else if (ch == charTab) {
  359.         AMWindow_DoTab ((AMWindow*) self, (curEvent.modifiers & optionKey) != 0);
  360.     } else if (focus != nil) {
  361.         keyCode = curEvent.message & keyCodeMask;
  362.         HandleControlKey (focus, keyCode, ch, curEvent.modifiers);
  363.         AMEngine_SetDirty (self->super.mDoc->mEngine);
  364.     } else {
  365.         SysBeep (1);
  366.     }
  367. }
  368.  
  369. /*----------*/
  370. void    Buttons_Resize (
  371.     Buttons*        self)
  372. {
  373.     /* application-specific code to resize items in window */
  374. }
  375.  
  376. /*----------*/
  377. void    Buttons_Scroll (
  378.     Buttons*        self,
  379.     short            newValue,
  380.     short            oldValue)
  381. {
  382.     /* application-specific code to scroll window */
  383.     if (gWhichScroll == self->super.vScroll) {
  384.     } else {    // horizontal
  385.     }
  386. }
  387.  
  388. //----------
  389. void    DoUndo (
  390.     Buttons*        self)
  391. {
  392. } // DoUndo
  393.  
  394. //----------
  395. void    DoCut (
  396.     Buttons*        self)
  397. {
  398.     TEHandle        curTE = AMWindow_GetCurTE ((AMWindow*) self);
  399.  
  400.     if (curTE != nil) {
  401.         TECut (curTE);
  402.         AMEngine_SetDirty (self->super.mDoc->mEngine);
  403.         scrapDirty = true;
  404.     }
  405. } // DoCut
  406.  
  407. //----------
  408. void    DoCopy (
  409.     Buttons*        self)
  410. {
  411.     TEHandle        curTE = AMWindow_GetCurTE ((AMWindow*) self);
  412.  
  413.     if (curTE != nil) {
  414.         TECopy (curTE);
  415.         scrapDirty = true;
  416.     }
  417. } // DoCopy
  418.  
  419. //----------
  420. void    DoPaste (
  421.     Buttons*        self)
  422. {
  423.     TEHandle        curTE = AMWindow_GetCurTE ((AMWindow*) self);
  424.  
  425.     if (curTE != nil) {
  426.         TEPaste (curTE);
  427.         AMEngine_SetDirty (self->super.mDoc->mEngine);
  428.     }
  429. } // DoPaste
  430.  
  431. //----------
  432. void    DoClear (
  433.     Buttons*        self)
  434. {
  435.     TEHandle        curTE = AMWindow_GetCurTE ((AMWindow*) self);
  436.  
  437.     if (curTE != nil) {
  438.         TEDelete (curTE);
  439.         AMEngine_SetDirty (self->super.mDoc->mEngine);
  440.     }
  441. } // DoClear
  442.  
  443. //----------
  444. void    DoSelectAll (
  445.     Buttons*        self)
  446. {
  447.     TEHandle        curTE = AMWindow_GetCurTE ((AMWindow*) self);
  448.  
  449.     if (curTE != nil) {
  450.         TESetSelect (0, 32767, curTE);
  451.     }
  452. } // DoSelectAll
  453.  
  454. //----------
  455. void    DoShowClipboard (
  456.     Buttons*        self)
  457. {
  458. } // DoShowClipboard
  459.  
  460. //----------
  461. Boolean        Buttons_DoCommand (
  462.     Buttons*        self,
  463.     long            inCommand)
  464. {
  465.     Boolean        result = true;
  466.  
  467.     switch (inCommand) {
  468.         case cmdUndo:
  469.                 DoUndo (self);
  470.             break;
  471.         case cmdCut:
  472.                 DoCut (self);
  473.             break;
  474.         case cmdCopy:
  475.                 DoCopy (self);
  476.             break;
  477.         case cmdPaste:
  478.                 DoPaste (self);
  479.             break;
  480.         case cmdClear:
  481.                 DoClear (self);
  482.             break;
  483.         case cmdSelectAll:
  484.                 DoSelectAll (self);
  485.             break;
  486.         case cmdShowClipboard:
  487.                 DoShowClipboard (self);
  488.             break;
  489.  
  490.         default:
  491.                 result = false;
  492.     } // switch
  493.  
  494.     return result;
  495. }
  496.